<?php

namespace App\Func;

use App\Models\Agenda\AgendaModel;

class AgendaFunc
{
    // 客户额度调整
    # 法务内部送审
    const AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_LAW = 101;
    # 信控内部送审
    const AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_CREDIT_CONTROL = 102;
    # 财务内部送审
    const AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_FINANCE = 103;
    # 部门内部送审
    const AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_DEPT = 104;
    # 客户信息待信控确认
    const AGENDA_TYPE_CLIENT_XK_CONFIRMED = 105;

    # 信用客户审批待处理
    const AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_CREDIT_CLIENT_JOIN = 105;



    // 合同
    // 合同法务审批
    const AGENDA_TYPE_CONTRACT_ADJUST_AMOUNT_LAW = 1001;


    #

	# 信用项目
	#
	public const AGENDA_TYPE_CREDIT_PROJECT_DEPARTMENT_LEADER_REVIEWING			= 4;	# 部门领导初步审查
	public const AGENDA_TYPE_CREDIT_PROJECT_CREDIT_MANAGER_REVIEW				= 5;	# 信控专员审查 
	public const AGENDA_TYPE_CREDIT_PROJECT_FINANCE_MANAGER_REVIEW				= 6;	# 财务专员审查
	public const AGENDA_TYPE_CREDIT_PROJECT_REVIEWING							= 7;	# 丁丁领导审查
	public const AGENDA_TYPE_CREDIT_PROJECT_AMOUNT_ADJUST_REVIEW				= 8;	# 调增调减审查





    /***
     *  通过 Code 查询对应字符串
     * @param $agendaType
     * @return string
     */
    public static function getAgendaTypeStr($agendaType){
        switch ($agendaType){
            case self::AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_CREDIT_CLIENT_JOIN:
                return "客户申请信用客户待处理";
            case self::AGENDA_TYPE_CONTRACT_ADJUST_AMOUNT_LAW:
                return "合同法务审批";
            case self::AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_LAW:
                return "信用客户额度调整法务审批";
            case self::AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_CREDIT_CONTROL:
                return "信用客户额度调整信控审批";
            case self::AGENDA_TYPE_CLIENT_ADJUST_AMOUNT_FINANCE:
                return "信用客户额度调整财务审批";
            case self::AGENDA_TYPE_CLIENT_XK_CONFIRMED:
                return "待信控确认生产评价表信息";

			# 信用项目
			#
			#
			case self::AGENDA_TYPE_CREDIT_PROJECT_DEPARTMENT_LEADER_REVIEWING		:{return '信用项目部门领导初步审查'	;}
			case self::AGENDA_TYPE_CREDIT_PROJECT_CREDIT_MANAGER_REVIEW				:{return '信用项目部门信控专员审查'		;}
			case self::AGENDA_TYPE_CREDIT_PROJECT_FINANCE_MANAGER_REVIEW			:{return '信用项目部门财务专员审查'		;}
			case self::AGENDA_TYPE_CREDIT_PROJECT_REVIEWING							:{return '信用项目部门丁丁钉钉领导审查'		;}
			case self::AGENDA_TYPE_CREDIT_PROJECT_AMOUNT_ADJUST_REVIEW				:{return '信用项目部门调增调减审查'		;}
            
			
			
			default:
                return "";
        }
    }



    /**
     * 创建待办
     * @param int $staffId
     * @param int $type
     * @return mixed
     */
    public static function addAgenda(int $staffId,int $type,int $sourceId){
        $agendaModel = new AgendaModel();
        return $agendaModel->addAgenda([
           'staff_id' => $staffId,
           'agenda_source_id' => $sourceId,
           'agenda_type' => $type
        ]);
    }

    public static function deleteAgenda($sourceId,$type){
        $agendaModel = new AgendaModel();
        return $agendaModel->editAgendaStatusBySourceAndTypeAndStaff(
            $sourceId,
            $type,
            TokenFuc::getCurrentStaffInfo()['staff_id'],
        );
    }

    /**
     * 校验对应待办是否完成
     * @param $sourceId
     * @param $type
     * @return bool
     */
    public static function checkerAgendaIsOverFulfil($sourceId,$type){
        $agendaModel = new AgendaModel();
        $okCount = $agendaModel->getAgendaStatusBySourceAndTypeOkStatusCount($sourceId,$type);
        $noCount = $agendaModel->getAgendaStatusBySourceAndTypeNoStatusCount($sourceId,$type);
        $sumCount = $agendaModel->getAgendaStatusBySourceAndTypeStatusCount($sourceId,$type);
        if($noCount == 0 && ($okCount == $sumCount)){
            return true;
        }
        return false;
    }

}